package com.cevent.yameng.web.mall.member.controller;

import java.util.Arrays;
import java.util.Map;

import com.cevent.yameng.web.mall.member.feign.CouponFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cevent.yameng.web.mall.member.entity.MemberEntity;
import com.cevent.yameng.web.mall.member.service.MemberService;
import com.cevent.common.utils.PageUtils;
import com.cevent.common.utils.R;



/**
 * 会员
 *
 * @author cevent
 * @email 1540001771@qq.com
 * @date 2020-09-14 13:32:00
 *
 * 对接coupon远程调用服务
 * //1.远程调用member会员，返回会员对应的优惠券
 *     //所有返回的数据类型都为R枚举
 *     @RequestMapping("/coupon/member/list")
 *     public R memberCoupons(){
 *         CouponEntity couponEntity=new CouponEntity();
 *         couponEntity.setCouponName("满100减10");
 *         //2.member远程调用coupon这里的R-memberCoupons
 *         return R.ok().put("memberCoupons",Arrays.asList(couponEntity));
 *     }
 */
@RestController
@RequestMapping("member/member")
public class MemberController {
    @Autowired
    private MemberService memberService;

    //1.注入Feign方法
    @Autowired
    private CouponFeignService couponFeignService;
    //1.coupon远程调用方法：获取会员优惠券
    @RequestMapping("/getMemberCouponTest")
    public R getMemberCouponTest(){
        MemberEntity memberEntity=new MemberEntity();
        memberEntity.setNickname("霹雳侠");
        R memberCoupons=couponFeignService.memberCoupons();
        //利用feign调用coupon-controller返回的参数名
        ;
        return R.ok().put("member",memberEntity).put("coupons",memberCoupons.get("memberCoupons"));
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("member:member:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("member:member:info")
    public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("member:member:save")
    public R save(@RequestBody MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("member:member:update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("member:member:delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
